import java.util.Arrays;

public class MyStak {
    public int[] elem;
    public int usedSize;

    public MyStak(){
        this.elem = new int[10];
    }
    //压栈
    public void push(int val){
        if(isFull()){
        elem = Arrays.copyOf(elem,2*elem.length);
        }
    elem[usedSize] = val;
    usedSize++;

    }
    public boolean isFull(){
        return usedSize == elem.length;
    }
    //出栈
    public int pop(){
        if(isEmpty()){
        throw new EmptyException("栈是空的");
        }
        int val = elem[usedSize-1];
        usedSize--;
        return val;
    }
    public boolean isEmpty(){
        return usedSize == 0;
    }

    public int peek(){
        if(isEmpty()){
            throw new EmptyException("栈是空的");
        }
        return elem[usedSize-1];
    }


}

